﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using TomNet.App.Core.Contracts;
using TomNet.App.Model.DB;
using TomNet.App.Model.DTO;
using TomNet.AspNetCore.Data;
using TomNet.SqlSugarCore.Entity;
using TomNet.Security.Claims;
using System.Security.Claims;
using TomNet.App.Model.DB.Identity;

namespace TomNet.App.Web.Controllers
{
    [Authorize]
    [Description("客户收益")]
    public class GuestIncomesController : Controller
    {
        private readonly IBusinessIncomeRunningsContract _businessIncomeRunningsContract;        
        private readonly IUnitOfWork _unitOfWork;
        public GuestIncomesController(IBusinessIncomeRunningsContract businessIncomeRunningsContract,            
            IUnitOfWork unitOfWork)
        {
            _businessIncomeRunningsContract = businessIncomeRunningsContract; 
            _unitOfWork = unitOfWork;
        }
        [Description("客户收益列表")]
        [HttpGet]
        public IActionResult GuestIncomesList()
        {
            return View();
        }
        [Description("客户收益列表")]
        [HttpPost]
        public IActionResult GuestIncomesList(int page = 1, int limit = 20)
        {
            var query = _businessIncomeRunningsContract.UnitOfWork.DbContext.Queryable<BusinessIncomeRunnings, Business,Users,UserRoleMap>((bi,b,u,urm)
                => bi.BusinessId == b.Id && b.UserId == u.Id && u.Id==urm.UserId)
               .Where((bi, b, u, urm) => bi.Id == 5)
               .OrderBy((bi, b, u,urm) => bi.Id, OrderByType.Desc)
              .Select((bi, b, u, urm) => new InterfaceIncomesDto
              {
                  UserId = u.Id,
                  UserName = u.UserName,
                  ProductName = b.ProductName,
                  Amount = bi.Amount,

              });
            int total = 0;
            var list = query.ToPageList(page, limit, ref total);
            var result = new LayuiPageResult<InterfaceIncomesDto>
            {
                Code = 0,
                Msg = "Success",
                Count = total,
                Data = list.ToArray()
            };

            return Json(result);
        }        
    }
}